<?php 
class TypeAttrController extends  CommonController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model=K("TypeAttr");
	}
	
	public function index(){
		$tid=Q('get.tid','','intval');
		$data=$this->model->where("shop_type_tid={$tid}")->all();
        $this->assign('data',$data);
		
		$this->display();
		}
		

	/**
	 * 属性添加
	 */
	public function add(){
		if(IS_POST){
			if(!$this->model->addAttr()) $this->error($this->model->error);
			$this->success('添加成功');
		}
		$this->display();
	}
	/**
	 * 编辑属性
	 */
	 public function edit(){
	 	if(IS_POST){
	 		if(!$this->model->editAttr()) $this->error($this->model->error);
			$this->success('编辑成功');
	 	}
		
		$taid=Q("get.taid");
		$oldData=$this->model->where("taid={$taid}")->find();
//		p($oldData);die;
		$this->assign("oldData",$oldData);
	  	$this->display();	  	
	  }
	/**
	   * 删除
	   */
	  public function del(){
	  	$taid=Q("get.taid");
		$attr=M("goods_attr")->where("shop_typeattr_taid={$taid}")->find();
		if($attr){
			$this->error("请先删除商品");
		}
		$this->model->where("taid={$taid}")->delete();
		$this->success("删除成功");
	  }
	  
	
	
	
}



 ?>